<?php

require_once(WSB_MODULES_PATH . 'sherpa/forms/SherpaForm.php');
require_once(WSB_MODULES_PATH . 'sherpa/validators/Coupon.php');

class Sherpa_Form_ApplyCoupon extends Sherpa_Form_SherpaForm
{

	/**
	 * Initialisierung
	 */
	public function init()
    {
    	$this->setName('coupon');

		// couponCode
        $element = new Zend_Form_Element_Text('couponCode');
        $element->setLabel('sherpaCouponCode');
        $element->addValidator(new Sherpa_Validator_Coupon());
        $element->addFilter(new Zend_Filter_StringTrim());
        $element->setDecorators(array(
	        'ViewHelper',
	        array('HtmlTag', array('tag' => 'td', 'class' => 'code')),
	        'Errors',
    	));
		$this->addElement($element);

    	// Button
        $element = new Zend_Form_Element_Image('btnApplyCoupon');
        $element->setLabel('sherpaButtonApplyCoupon');
        $element->setAttrib('src', 'sherpa/img/btn-uebernehmen.gif');
        $element->setDecorators(array(
	        'ViewHelper',
	        'Errors',
	        array('HtmlTag', array('tag' => 'td', 'class' => 'button'))
    	));
		$this->addElement($element);

		// Form Dekoratoren
    	$formName = $this->getName();
		$this->clearDecorators();
        $this->addDecorator('FormElements')
             ->addDecorator('HtmlTag', array('tag' => 'table', 'cellspacing' => 0, 'class' => empty($formName) ? 'default-form' : $formName ))
             ->addDecorator('Form');

    }

    /**
     * @param float $subtotal
     */
    public function addSubtotalHiddenElement($subtotal)
    {
        $element = new Zend_Form_Element_Hidden('subtotal');
        $element->setValue($subtotal);
        $element->setDecorators(array(
	        'ViewHelper',
	        array('HtmlTag', array('tag' => 'td', 'style' => 'display:none'))
    	));
		$this->addElement($element);
    }

}